home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 4
/
Mac Giga-ROM 4.0 - 1993.toast
/
FILES
/
CDE
/
I-N
/
MCM-InitShare.cpt
/
cdev.p
< prev
next >
Wrap
Text File
|
1988-06-23
|
5KB
|
217 lines
UNIT RunINITs;
{-----} INTERFACE {---------------------------------------------------------}
USES
{$LOAD MQOTP.dump}
Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf;
FUNCTION Main (message, item, numItems, CPanelID: INTEGER;
theEvent: EventRecord; cdevValue: LONGINT;
CPDialog: DialogPtr): LONGINT;
{-----} IMPLEMENTATION {----------------------------------------------------}
TYPE
cdevStorRec = RECORD
button : INTEGER; { our number + offset }
pathRsrc : StringHandle; { handle to our resource }
modified : BOOLEAN; { flag }
pathStr : STR255; { current path name }
pathItem : Handle; { item handle }
pathRect : Rect; { item rect }
END;
cdevStorPtr = ^cdevStorRec;
cdevStorHdl = ^cdevStorPtr;
FUNCTION DoInit (CPDialog: DialogPtr; numItems: INTEGER): LONGINT; FORWARD;
PROCEDURE DoHit (storHdl: cdevStorHdl; item: INTEGER); FORWARD;
PROCEDURE DoClose (storHdl: cdevStorHdl); FORWARD;
{-----------------------------------------------------------------------------}
FUNCTION Main (message, item, numItems, CPanelID: INTEGER;
theEvent: EventRecord; cdevValue: LONGINT;
CPDialog: DialogPtr): LONGINT;
BEGIN
IF ((cdevValue < -1) OR (cdevValue > 1)) THEN
CASE message OF
initDev:
cdevValue := DoInit (CPDialog, numItems);
hitDev:
DoHit (cdevStorHdl(cdevValue), item);
closeDev:
BEGIN
DoClose (cdevStorHdl(cdevValue));
cdevValue := 0;
END;
OTHERWISE
END;
Main := cdevValue;
END;
{-----------------------------------------------------------------------------}
{ GetWDPathName -- return path name of working directory }
FUNCTION GetWDPathName (wdRefNum: INTEGER): Str255;
{ The low-level File Manager routine PBGetCatInfo uses the Catalog
Info Parameter Block Record (CInfoPBRec) for transferring
information. The input parameters are:
ioCompletion -- completion routine,
ioNamePtr -- path name,
ioVRefNum -- working directory reference number,
ioDrDirID -- directory ID or file number,
ioFDirIndex -- index.
We use a synchronous call, which causes ioCompletion to be set to
NIL by the File Manager.
If both ioVRefNum and ioDrDirID are provided, ioDrDirID is used to
identify the directory on the volume indicated by ioVRefNum. If
ioDrDirID is set to zero, ioVRefNum is used.
A negative value of ioFDirIndex causes the File Manager to ignore
ioNamePtr.
The relevant output parameters are:
ioNamePtr -- path name,
ioDrDirID -- directory ID or file number,
ioDrParID -- parent directory ID.
If ioDrDirID is zero on input, it is set to the directory ID of
the working directory on output. If ioDrDirID is nonzero on input
its value does not change.
}
VAR
params : CInfoPBRec;
theErr : OSErr;
tempName : Str255;
pathName : Str255;
BEGIN
pathName := '';
WITH params DO BEGIN
ioVRefNum := wdRefNum;
ioFDirIndex := -1; { don't use ioNamePtr for input }
ioNamePtr := @tempName;
ioDrDirID := 0; { use working directory reference number
on the first pass through the loop }
END;
REPEAT
params.ioDrDirID := params.ioDrParID;
theErr := PBGetCatInfo (@params, FALSE);
pathName := ConCat (tempName, ':', pathName);
UNTIL (params.ioDrDirID = 2);
GetWDPathName := pathName;
END;
{-----------------------------------------------------------------------------}
FUNCTION DoInit (CPDialog: DialogPtr; numItems: INTEGER): LONGINT;
CONST
versItem = 1;
infoItem = 2;
nameItem = 3;
changeItem = 4;
pathStrID = -4048;
VAR
tempHdl : StringHandle;
storHdl : cdevStorHdl;
itemType : INTEGER;
BEGIN
tempHdl := GetString (pathStrID);
IF (tempHdl = NIL) THEN BEGIN
IF (ResError = resNotFound) THEN
DoInit := cdevResErr
ELSE
DoInit := cdevMemErr;
EXIT (DoInit);
END;
storHdl := cdevStorHdl (NewHandle (SIZEOF (cdevStorRec)));
IF (storHdl = NIL) THEN BEGIN
DoInit := cdevMemErr;
EXIT (DoInit);
END;
WITH storHdl^^ DO BEGIN
button := numItems + changeItem;
pathRsrc := tempHdl;
modified := FALSE;
pathStr := pathRsrc^^;
GetDItem (CPDialog, numItems+nameItem, itemType, pathItem, pathRect);
SetIText (pathItem, pathStr);
END;
DoInit := ORD4 (storHdl);
END;
{-----------------------------------------------------------------------------}
PROCEDURE DoHit (storHdl: cdevStorHdl; item: INTEGER);
VAR
thePoint: Point;
typeList: SFTypeList;
reply: SFReply;
BEGIN
WITH storHdl^^ DO
IF (item = button) THEN BEGIN
thePoint.v := 100;
thePoint.h := 100;
SFGetFile (thePoint, '', NIL, -1, typeList, NIL, reply);
IF reply.good THEN BEGIN
pathStr := GetWDPathName (reply.vRefNum);
SetIText (pathItem, pathStr);
InvalRect (pathRect);
modified := TRUE;
END;
END;
END;
{-----------------------------------------------------------------------------}
PROCEDURE DoClose (storHdl: cdevStorHdl);
BEGIN
IF (storHdl <> NIL) THEN BEGIN
WITH storHdl^^ DO
IF (modified) THEN BEGIN
HNoPurge (Handle(pathRsrc));
SetString (pathRsrc, pathStr);
ChangedResource (Handle(pathRsrc));
WriteResource (Handle(pathRsrc));
HPurge (Handle(pathRsrc));
END;
DisposHandle (Handle (storHdl));
END;
END;
END.